package com.ai.module.suno.service;

import com.ai.module.chat.common.domain.BasePage;
import com.ai.module.suno.domain.bo.SunoInfo;
import com.ai.module.suno.domain.bo.SunoInfoTask;
import com.ai.module.suno.domain.req.SunoReq;
import com.ai.module.suno.domain.vo.SunoGenerateVo;
import com.ai.module.suno.domain.vo.SunoRecordVo;
import com.ai.module.suno.domain.vo.UserSunoVo;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;

import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.List;

public interface SunoService {

    void loadCookie();

    SunoInfoTask fetch(String id);

    public static void downloadFile(InputStream inputStream, String filename) {
        byte[] buffer = new byte[1024];
        File file = new File("C:\\Users\\14550\\Desktop\\2024\\suno\\" + filename);
        BufferedInputStream bis = null;
        try {
            FileOutputStream os = new FileOutputStream(file);

            bis = new BufferedInputStream(inputStream);
            int i = bis.read(buffer);
            while (i != -1) {
                os.write(buffer, 0, i);
                i = bis.read(buffer);
            }
        } catch (Exception e) {

        } finally {
            if (bis != null) {
                try {
                    bis.close();
                } catch (IOException e) {
                }
            }
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                }
            }
        }

    }

    void download(String fileName, HttpServletResponse response);


    JSONObject generate(SunoGenerateVo sunoGenerate);

    IPage<UserSunoVo> sunoRecord(SunoReq page);

    SunoRecordVo sunoDetail(String sunoId);

}
